<template>
  <div class="echartsBox">
    <div id="materilCurrentApplyLine" class="allWidthHeight" />
  </div>
</template>
<script>
import * as echarts from 'echarts'
export default {
  props: {},
  data() {
    return {
      myChart2: null,
      value1: ''
    }
  },
  watch: {},
  mounted() {},
  methods: {
    infoSize() {
      this.myChart2.resize()
    },
    /* 设备时段echarts */
    setMaterilCurrentApplyLine(data) {
      const option = {
        grid: {
          left: '10%', // 距离左侧的距离
          right: '2%', // 距离右侧的距离
          top: '22%', // 距离顶部的距离
          bottom: '12%' // 距离底部的距离
        },
        legend: {
          data: ['原材消耗量', '原材库存量', '成品量'],
          right: '0',
          top: '0',
          textStyle: {
            fontSize: '12px',
            color: '#fff' // 这里设置图例的字体颜色为红色
          },
          itemWidth: 10, // 设置图例标记的图形宽度
          itemHeight: 10 // 设置图例标记的图形高度
        },
        xAxis: [
          {
            splitLine: { show: false },
            axisPointer: {
              type: 'shadow'
            },
            axisLine: {
              // 坐标轴 轴线
              lineStyle: {
                color: '#fff',
                width: 1,
                type: 'solid'
              }
            },
            axisLabel: {
              color: '#fff',
              formatter: '{value}',
              interval: 0 // 代表显示所有x轴标签显示
            },
            axisTick: {
              show: false
            },
            type: 'category',
            data: ['11-1', '11-2', '11-3', '11-4', '11-5', '11-6', '11-7']
          }
        ],
        yAxis: [
          {
            axisLabel: {
              show: true,
              color: '#fff'
            },
            type: 'value'
          }
        ],
        dataZoom: [
          {
            type: 'inside'
          }
        ],
        series: [
          {
            name: '原材消耗量',
            type: 'bar',
            data: [4200, 2000, 4000, 3200, 3500, 2500, 3700],
            itemStyle: { color: '#28CEAB' }
          },
          {
            name: '原材库存量',
            type: 'bar',
            data: [4200, 500, 2000, 2200, 2500, 1500, 2700],
            itemStyle: { color: '#217CE1' }
          },
          {
            name: '成品量',
            type: 'bar',
            data: [4200, 500, 2000, 2200, 2500, 1500, 2700],
            itemStyle: { color: '#217CE1' }
          }
        ]
      }
      if (
        this.myChart2 != null &&
        this.myChart2 !== '' &&
        this.myChart2 !== undefined
      ) {
        this.myChart2.dispose() // 销毁
      }
      this.myChart2 = echarts.init(
        document.getElementById('materilCurrentApplyLine')
      )
      this.myChart2.clear()
      this.myChart2.setOption(option, true)
    }
  }
}
</script>
<style lang='scss' scoped>
.echartsBox {
  width: 100%;
  padding: 0 15px;
  height: 100%;
}
</style>
